<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>monotonic_resource</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter 1. Boost.JSON">
<link rel="up" href="../ref.html" title="This Page Intentionally Left Blank 2/2">
<link rel="prev" href="boost__json__memory_resource.html" title="memory_resource">
<link rel="next" href="boost__json__monotonic_resource/monotonic_resource.html" title="monotonic_resource::monotonic_resource">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost__json__memory_resource.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost__json__monotonic_resource/monotonic_resource.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="json.ref.boost__json__monotonic_resource"></a><a class="link" href="boost__json__monotonic_resource.html" title="monotonic_resource">monotonic_resource</a>
</h4></div></div></div>
<p>
        A dynamically allocating resource with a trivial deallocate.
      </p>
<h5>
<a name="json.ref.boost__json__monotonic_resource.h0"></a>
        <span class="phrase"><a name="json.ref.boost__json__monotonic_resource.synopsis"></a></span><a class="link" href="boost__json__monotonic_resource.html#json.ref.boost__json__monotonic_resource.synopsis">Synopsis</a>
      </h5>
<p>
        Defined in header <code class="literal">&lt;<a href="https://github.com/cppalliance/json/blob/master/include/boost/json/monotonic_resource.hpp" target="_top">boost/json/monotonic_resource.hpp</a>&gt;</code>
      </p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">monotonic_resource</span> <span class="special">:</span>
    <span class="keyword">public</span> <span class="identifier">memory_resource</span>
</pre>
<h5>
<a name="json.ref.boost__json__monotonic_resource.h1"></a>
        <span class="phrase"><a name="json.ref.boost__json__monotonic_resource.member_functions"></a></span><a class="link" href="boost__json__monotonic_resource.html#json.ref.boost__json__monotonic_resource.member_functions">Member
        Functions</a>
      </h5>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Name
                </p>
              </th>
<th>
                <p>
                  Description
                </p>
              </th>
</tr></thead>
<tbody>
<tr>
<td>
                <p>
                  <span class="bold"><strong><a class="link" href="boost__json__monotonic_resource/monotonic_resource.html" title="monotonic_resource::monotonic_resource">monotonic_resource</a> <span class="silver">[constructor]</span></strong></span>
                </p>
              </td>
<td>
                <p>
                  Constructor. <br> <span class="silver">—</span><br> Copy
                  constructor (deleted)
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <span class="bold"><strong><a class="link" href="boost__json__monotonic_resource/operator_eq_.html" title="monotonic_resource::operator=">operator=</a></strong></span>
                </p>
              </td>
<td>
                <p>
                  Copy assignment (deleted)
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <span class="bold"><strong><a class="link" href="boost__json__monotonic_resource/release.html" title="monotonic_resource::release">release</a></strong></span>
                </p>
              </td>
<td>
                <p>
                  Release all allocated memory.
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  <span class="bold"><strong><a class="link" href="boost__json__monotonic_resource/_dtor_monotonic_resource.html" title="monotonic_resource::~monotonic_resource">~monotonic_resource</a> <span class="silver">[destructor]</span></strong></span>
                </p>
              </td>
<td>
                <p>
                  Destructor.
                </p>
              </td>
</tr>
</tbody>
</table></div>
<h5>
<a name="json.ref.boost__json__monotonic_resource.h2"></a>
        <span class="phrase"><a name="json.ref.boost__json__monotonic_resource.description"></a></span><a class="link" href="boost__json__monotonic_resource.html#json.ref.boost__json__monotonic_resource.description">Description</a>
      </h5>
<p>
        This memory resource is a special-purpose resource that releases allocated
        memory only when the resource is destroyed (or when <a class="link" href="boost__json__monotonic_resource/release.html" title="monotonic_resource::release"><code class="computeroutput"><span class="identifier">release</span></code></a> is called). It has a trivial
        deallocate function; that is, the metafunction <a class="link" href="boost__json__is_deallocate_trivial.html" title="is_deallocate_trivial"><code class="computeroutput"><span class="identifier">is_deallocate_trivial</span></code></a> returns <code class="computeroutput"><span class="keyword">true</span></code>.
      </p>
<p>
        The resource can be constructed with an initial buffer. If there is no initial
        buffer, or if the buffer is exhausted, subsequent dynamic allocations are
        made from the system heap. The size of buffers obtained in this fashion follow
        a geometric progression.
      </p>
<p>
        The purpose of this resource is to optimize the use case for performing many
        allocations, followed by deallocating everything at once. This is precisely
        the pattern of memory allocation which occurs when parsing: allocation is
        performed for each parsed element, and when the the resulting <a class="link" href="boost__json__value.html" title="value"><code class="computeroutput"><span class="identifier">value</span></code></a> is no longer needed, the entire
        structure is destroyed. However, it is not suited for modifying the value
        after parsing is complete; reallocations waste memory, since the older buffer
        is not reclaimed until the resource is destroyed.
      </p>
<h5>
<a name="json.ref.boost__json__monotonic_resource.h3"></a>
        <span class="phrase"><a name="json.ref.boost__json__monotonic_resource.example"></a></span><a class="link" href="boost__json__monotonic_resource.html#json.ref.boost__json__monotonic_resource.example">Example</a>
      </h5>
<p>
        This parses a JSON into a value which uses a local stack buffer, then prints
        the result.
      </p>
<pre class="programlisting"><span class="keyword">unsigned</span> <span class="keyword">char</span> <span class="identifier">buf</span><span class="special">[</span> <span class="number">4000</span> <span class="special">];</span>
<span class="identifier">monotonic_resource</span> <span class="identifier">mr</span><span class="special">(</span> <span class="identifier">buf</span> <span class="special">);</span>

<span class="comment">// Parse the string, using our memory resource</span>
<span class="keyword">auto</span> <span class="keyword">const</span> <span class="identifier">jv</span> <span class="special">=</span> <span class="identifier">parse</span><span class="special">(</span> <span class="string">"[1,2,3]"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">mr</span> <span class="special">);</span>

<span class="comment">// Print the JSON</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">jv</span><span class="special">;</span>
</pre>
<h5>
<a name="json.ref.boost__json__monotonic_resource.h4"></a>
        <span class="phrase"><a name="json.ref.boost__json__monotonic_resource.remarks"></a></span><a class="link" href="boost__json__monotonic_resource.html#json.ref.boost__json__monotonic_resource.remarks">Remarks</a>
      </h5>
<p>
        The total amount of memory dynamically allocated is monotonically increasing;
        That is, it never decreases.
      </p>
<h5>
<a name="json.ref.boost__json__monotonic_resource.h5"></a>
        <span class="phrase"><a name="json.ref.boost__json__monotonic_resource.thread_safety"></a></span><a class="link" href="boost__json__monotonic_resource.html#json.ref.boost__json__monotonic_resource.thread_safety">Thread Safety</a>
      </h5>
<p>
        Members of the same instance may not be called concurrently.
      </p>
<h5>
<a name="json.ref.boost__json__monotonic_resource.h6"></a>
        <span class="phrase"><a name="json.ref.boost__json__monotonic_resource.see_also"></a></span><a class="link" href="boost__json__monotonic_resource.html#json.ref.boost__json__monotonic_resource.see_also">See
        Also</a>
      </h5>
<p>
        <a href="https://en.wikipedia.org/wiki/Region-based_memory_management" target="_top">https://en.wikipedia.org/wiki/Region-based_memory_management</a>
      </p>
<p>
        Convenience header <code class="literal">&lt;<a href="https://github.com/cppalliance/json/blob/master/include/boost/json.hpp" target="_top">boost/json.hpp</a>&gt;</code>
      </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2019, 2020 Vinnie Falco<br>Copyright © 2020 Krystian Stasiowski<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost__json__memory_resource.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost__json__monotonic_resource/monotonic_resource.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
